<?php

set_time_limit(0);

include ('.././config.php');
include ('.././includes/functions.php');
include ('.././includes/functions/system.php');
include ('.././includes/functions/db.php');

$db = new Dbaccess;
$db->connect ( $dbi['sql_host'], $dbi['sql_username'], $dbi['sql_password'], $dbi['sql_dbname'] ) or error('Critial Error', mysql_error () );

// Unset all sql datails for the security purposes
unset ( $dbi );

?>
<html>
<head>
	<title>phpMyRealty Installer</title>
</head>

<body bgcolor="white">

<div align="center">

<table width="60%" border="0" cellpadding="10">
<tr>
	<td width="20%" align="center" valign="top" style="border-right : 1px dotted #BABABA;">
    <img src="./images/installer.png" alt="">
    </td>
    <td width="80%" align="left" valign="top">

    <p><span style="font-family : verdana; font-size : 25px; color : #5678A2;">phpMyRealty <?php echo VERSION; ?> Installation Script</span><br /><br />
    <span style="font-family : verdana; font-size : 12px; color : #BB5555;">(Please remove the /install and /docs directories from the host after you have installed the script).</span><br /><br />
    <span style="font-family : verdana; font-size : 15px; font-weight : bold; color : #5678A2;">Server Configuration:</span><br /><br />
    <span style="font-family : verdana; font-size : 12px; color : #333333;">

	<?php
	
	$result = $db->query ('SELECT VERSION() AS version');
	if ($result != FALSE && @mysql_num_rows($result) > 0) {
		$row   = $db->fetcharray ($result);
		$match = explode('.', $row['version']);
	}
	
	echo 'MySQL: <strong>' . $row['version'] . '</strong> (3.23.23+ required)<br />';
	echo 'PHP: <strong>' . phpversion() . '</strong> (4.3.x+ required)<br />';
	echo 'GD: <strong>' . gd_version() . '</strong> (2.x required)<br />';
	
	?>

    <br />

    </span>

    <span style="font-family : verdana; font-size : 15px; font-weight : bold; color : #5678A2;">Creating Database Tables:</span><br /><br />
    <span style="font-family : verdana; font-size : 10px; color : #333333;">

<?php

// CONFIGURATION TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . CONFIGURATION_TABLE . ' (
	name varchar(50) DEFAULT NULL, val varchar(255) DEFAULT NULL, descr VARCHAR(255)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("website_name_short", "YourSiteName.com", "The short name of your website for title tag")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("website_name", "YourSiteName.com - The Best Real Estate Website", "The name of your website")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("title_meta", "YourSiteName.com - The Best Real Estate Website", "Global template meta title")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("description_meta", "YourSiteName.com is The Best Real Estate Website", "Global template meta keywords")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("keywords_meta", "php, sql, mysql, script, real, estate, immovable property, directory", "Global template meta keywords")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("robots_meta", "index, follow", "Global template meta robots")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("general_e_mail", "info@phpmyrealty.com", "Default FROM e-mail address to send messages to the users")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("general_e_mail_name", "YourSiteName.com", "Default FROM name to send messages to the users")') or error('Critical Error', mysql_error () );
 
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("language", "english", "Default language name")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("template", "default", "Default template name")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gzip", "OFF", "Enable pages GZip compression for lower host traffic (ON/OFF)")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("rewrite", "OFF", "Enable mod_rewrite Apache module support for better SEO (ON/OFF)")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("timings", "OFF", "Enable debug information in the bottom of each page")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("currency", "USD", "Default currency")') or error('Critical Error', mysql_error () );
 
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("type_rows", "2", "Number of rows in the Property Type Module, can be 1 or 2.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("approve_realtors", "OFF", "Shall administrator approve new realtors or add them into the database automatically (ON/OFF).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("approve_listings", "OFF", "Shall administrator approve new listings or add them into the database automatically (ON/OFF).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_number_of_listings", "99", "Maximum Number of Listings allowed for each realtor.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_number_of_photos", "99", "Maximum Number of images per listing in Photo Gallery allowed for each realtor.")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("new_days", "5", "Will keep listing NEW during this number of days.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("updated_days", "5", "Will keep listing UPDATED during this number of days.")') or error('Critical Error', mysql_error () );
 
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("featured_limit", "3", "Number of listing to show in the featured listings module")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("most_visited_limit", "6", "Number of listing to show in the most visited listings module")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("recent_limit", "6", "Number of listing to show in the recent listings module")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("visited_limit", "3", "Number of Recently Visited Listings to store and show")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("search_results", "10", "Number of listing to show per page in the search section")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("search_description", "150", "Number of characters per description to show in the search results")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("realtor_description_size", "2500", "Size of a Realtor Description Field.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("listing_description_size", "2500", "Size of a Listing Description Field.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("listing_directions_size", "500", "Size of a Listing Directions Field.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gallery_description_size", "500", "Size of a Photo Gallery Description Field.")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("mailer_message_size", "200", "Maximum size of a message sent to a user via mailer.")') or error('Critical Error', mysql_error () );
 
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_photo_width", "640", "Maximum width of a Realtor photo allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_photo_height", "480", "Maximum height of a Realtor photo allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_photo_size", "102400", "Maximum size of a Realtor photo file allowed to upload (Bytes).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("photo_resampled_width", "150", "Resize a Realtor photo to this width (pixels).")') or error('Critical Error', mysql_error () );

// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_image_width", "640", "Maximum width of a listing main image allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_image_height", "480", "Maximum height of a listing main image allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_image_size", "102400", "Maximum size of a listing main image file allowed to upload (Bytes).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("image_resampled_width", "150", "Resize a listing main image to this width (pixels).")') or error('Critical Error', mysql_error () );

// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_gallery_width", "640", "Maximum width of a listing photo gallery image allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_gallery_height", "480", "Maximum height of a listing photo gallery image allowed to upload (pixels).")') or error('Critical Error', mysql_error () );
// $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("max_gallery_size", "102400", "Maximum size of a listing photo gallery image file allowed to upload (Bytes).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gallery_resampled_width", "150", "Resize a listing photo gallery image to this width (pixels).")') or error('Critical Error', mysql_error () );
 
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gallery_window_width", "660", "Photo Gallery full size image window width (pixels).")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gallery_window_height", "550", "Photo Gallery full size image window height (pixels).")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("list_background_color_even", "#F1F1F1", "Background color for all even search results listings cells")') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("price_range_min", "50000", "Search Form: Minimum Property Price Range")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("price_range_max", "1000000", "Search Form: Maximum Property Price Range")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("price_range_step", "50000", "Search Form: Property Price Range Step")') or error('Critical Error', mysql_error () );

// New in 1.0.2
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("banner_width", "468", "Banner Ad maximum width allowed")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("banner_height", "120", "Banner Ad maximum height allowed")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("banner_size", "51200", "Banner Ad maximum size in Bytes")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("banner_featured", "OFF", "Show banners for featured listings only. (ON/OFF)")') or error('Critical Error', mysql_error () );
//

// New in 1.0.3
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("paypal_email", "me@domain.com", "Your PRIMARY paypal email address")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("paypal_currency", "USD", "Paypal currency, USD, GBP etc.")') or error('Critical Error', mysql_error () );
//

// New in 1.0.5
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("2co_user_id", "", "2co User ID")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("2co_secret_word", "", "2co Secret Word")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("2co_gateway", "https://www2.2checkout.com/2co/buyer/purchase", "2co Default Gateway URL")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("gateway", "1", "Default Payment Gateway (1 for PayPal, 2 for 2checkout)")') or error('Critical Error', mysql_error () );
//
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("google_key", "", "Google Maps Key, get it here: http://www.google.com/apis/maps/signup.html")') or error('Critical Error', mysql_error () );
// New in 1.0.4
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_listings", "5", "Free Agent Package Number of Listings Allowed")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_gallery", "5", "Free Agent Package Number of Photo Gallery Images Allowed")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_mainimage", "ON", "Free Agent Package Show Main Property Image (ON/OFF)")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_photo", "ON", "Free Agent Package Show Agent Photo/Logo (ON/OFF)")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_phone", "ON", "Free Agent Package Show Agent Phone/Fax/Mobile (ON/OFF)")') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("free_address", "ON", "Free Agent Package Show Agent and Property Address (ON/OFF)")') or error('Critical Error', mysql_error () );
//

// New in 2.0.0
 $db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("path_to_mencoder", "/usr/bin/mencoder", "Path to mencoder tool. Default /usr/bin/mencoder")') or error('Critical Error', mysql_error () );
 
// New in 3.2
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("mencoder", "OFF", "Enable MEncoder for video conversion. Most servers do not support this by default. If disabled, you can still upload FLV files for video tours. (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("quick_search", "ON", "Enable or disable the \'Quick Search\' from displaying on the left-hand side of the site (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("featured_listings", "ON", "Enable or disable featured listings from displaying on the index page (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("all_listings", "OFF", "Enable or disable showing all listings, not just featured, randomly on the index page (ON/OFF)")') or error('(2) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("recent_listings", "ON", "Enable or disable recent listings/agents and most visited listings on the index page at the bottom of the page (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("main_search", "ON", "Enable or disable the main search (WHAT / WHERE / OPTIONS) at the top of the index page (ON/OFF)")') or error('(3) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("main_map", "OFF", "Enable or disable the map from appearing on the index page (Must have Google Maps API key installed in order to show) (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("featured_agents", "OFF", "Enable or disable featured agents from displaying on the index page (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("settings_box", "ON", "Enable or disable the \'Settings\' box from displaying with Language/Template options (ON/OFF)")') or error('(4) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("online_box", "ON", "Enable or disable the \'Online\' box from displaying with logged-in agents currently online (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("all_agents", "OFF", "Enable or disable showing all agents, not just featured, randomly on the index page (ON/OFF)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("expired_listings", "1", "What should happen to listings that have expired? (1 - Disable Listing, 2 - Delete Listing)")') or error('(5) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("contact_agents", "1", "Specify who has access to listing contact information. (1 - Everyone, 2 - Registered account holders only, 3 - Paid account holders only)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("slideshow_main", "ON", "Enable or disable the \'Slideshow\' box from displaying on the main page (ON/OFF)")') or error('(7) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("slideshow_type", "1", "Specify whether the slideshow should grab all listings or featured listings only (1 - Featured only (random), 2 - All listings (random))")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("slideshow_speed", "5000", "Specify the slideshow scroll speed. Note: This is in milliseconds (5000 = 5 seconds. 10000 = 10 seconds)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("slideshow_visibility", "2", "Specify how many properties should be visible in the slideshow at a time")') or error('(6) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("map_zoom", "5", "Specify how zoomed out the map should be on pages that have a map. (1 - zoomed in all the way. 10 - zoomed out all the way. Can be anything from 1 - 10.)")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("map_height", "400", "Specify the Google Map height on all pages that have a map. (E.g., 400 - 400 pixels wide")') or error('(8) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("map_width", "500", "Specify the Google Map width on all pages that have a map. (E.g., 500 - 500 pixels in height")') or error('(9) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("expire_notice", "5", "Specify the number of days in advance a seller should be e-mailed that their package is going to expire (5 - 5 days, 14 - 2 weeks")') or error('(1) critical Error', mysql_error () );
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) VALUES ("show_calendar", "ON", "Enable or disable showing the availability calendar (ON/OFF)")') or error('(1) critical Error', mysql_error () );

$db->query('ALTER TABLE ' . CONFIGURATION_TABLE . ' ADD UNIQUE `UniqueNames` (`name`)') or error('(1) Critical Error', mysql_error () );

// New in 3.2.3
$db->query('INSERT IGNORE INTO ' . CONFIGURATION_TABLE . ' (name, val, descr) 
    VALUES ("show_mls", "ON", "Enable or disable showing the MLS field (ON/OFF)"),
           ("show_postal_code", "ON", "Enable or disable showing the ZIP code field (ON/OFF)"),
           ("paypal_mode", "LIVE", "Production PayPal payment gateway (LIVE) or the sandbox test environment (TEST)."),
           ("free_listings_expire", "0", "Number of days after which a free listing expires (0 = no expiration)."),
           ("slideshow_limit", 25, "Number of listings to show in the slideshow module"),
           ("allow_same_title", "OFF", "Allow duplicate listing property titles (ON/OFF)"),
           ("allow_same_e_mail", "OFF", "Allow multiple accounts with same e-mail address (ON/OFF)"),
           ("price_monthly_range_min", "0", "Search Form: Minimum Monthly Rental Price Range"),
           ("price_monthly_range_max", "10000", "Search Form: Maximum Monthly Rental Price Range"),
           ("price_monthly_range_step", "500", "Search Form: Monthly Rental Price Range Step"),
           ("decimal_point", ".", "Character to use as decimal point (number formatting)"),
           ("1000_separator", ",", "Character to use as thousands separator (number formatting)")'); 

echo 'Configuration table created and populated<br />';

// TYPES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . TYPES_TABLE . ' (
	name varchar(50) DEFAULT NULL,
	name2 varchar(50) DEFAULT NULL,
	name3 varchar(50) DEFAULT NULL,
	name4 varchar(50) DEFAULT NULL,
	name5 varchar(50) DEFAULT NULL,
	name6 varchar(50) DEFAULT NULL,
	name7 varchar(50) DEFAULT NULL,
	name8 varchar(50) DEFAULT NULL,
	name9 varchar(50) DEFAULT NULL,
	name10 varchar(50) DEFAULT NULL,
	name11 varchar(50) DEFAULT NULL,
	name12 varchar(50) DEFAULT NULL,
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	counter int(10) DEFAULT \'0\' NOT NULL,
	id int(5) UNSIGNED auto_increment,
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Single Family Home", 1, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Condo / Townhouse / Co-op", 2, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Multi-Family Home", 3, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Mfd / Mobile Home", 4, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Land", 5, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Farms", 6, 0)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES_TABLE . ' (name, id, counter) VALUES ("Rentals", 7, 0)') or error('Critical Error', mysql_error () );

echo 'Property Types table created and populated<br />';

// STYLES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . STYLES_TABLE . ' (
	name varchar(50) DEFAULT NULL,
	name2 varchar(50) DEFAULT NULL,
	name3 varchar(50) DEFAULT NULL,
	name4 varchar(50) DEFAULT NULL,
	name5 varchar(50) DEFAULT NULL,
	name6 varchar(50) DEFAULT NULL,
	name7 varchar(50) DEFAULT NULL,
	name8 varchar(50) DEFAULT NULL,
	name9 varchar(50) DEFAULT NULL,
	name10 varchar(50) DEFAULT NULL,
	name11 varchar(50) DEFAULT NULL,
	name12 varchar(50) DEFAULT NULL,
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment,
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . STYLES_TABLE . ' (name, id) VALUES ("A-Frame", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . STYLES_TABLE . ' (name, id) VALUES ("Colonial", 2)') or error('Critical Error', mysql_error () );

echo 'Styles table created and populated<br />';

// USERS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . USERS_TABLE . ' (
	id int(10) UNSIGNED auto_increment, 
	approved tinyint(1) UNSIGNED DEFAULT \'0\', 
	package int(10) UNSIGNED DEFAULT \'0\',
	first_name varchar(255) DEFAULT NULL, 
	last_name varchar(255) DEFAULT NULL,
	company_name varchar(255) DEFAULT NULL,
	description text, 
	location smallint(5) UNSIGNED DEFAULT \'0\', 
	city varchar(50) DEFAULT NULL, 
	zip varchar(20) DEFAULT NULL, 
	address varchar(255) DEFAULT NULL,
	phone varchar(50) DEFAULT NULL,
	fax varchar(50) DEFAULT NULL,
	mobile varchar(50) DEFAULT NULL,
	email varchar(50) DEFAULT NULL,
	website varchar(255) DEFAULT NULL,
	rating mediumint(8) UNSIGNED DEFAULT \'0\', 
	votes mediumint(8) UNSIGNED DEFAULT \'0\', 
	date_added varchar(10) DEFAULT NULL, 
	date_updated varchar(10) DEFAULT NULL,
	date_upgraded varchar(10) DEFAULT NULL,
	ip_added text,
	ip_updated text,
	ip_upgraded text,
	number varchar(255) DEFAULT NULL,
	login varchar(50) DEFAULT NULL,
	password varchar(32) DEFAULT NULL,
	hits int(5) UNSIGNED DEFAULT \'0\',
	image_uploaded tinyint(1) UNSIGNED DEFAULT \'0\', 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Users table created<br />';

// New in 3.2.3
// CUSTOM FIELDS / VALUES TABLES

$db->query("CREATE TABLE IF NOT EXISTS `".FIELDS_TABLE."` (
          `id` mediumint(5) NOT NULL auto_increment,
          `name` varchar(50) NOT NULL,
          `type` enum('select','input','textarea') NOT NULL,
          `name2` varchar(255) NOT NULL,
          `name3` varchar(255) NOT NULL,
          `name4` varchar(255) NOT NULL,
          `name5` varchar(255) NOT NULL,
          `name6` varchar(255) NOT NULL,
          `name7` varchar(255) NOT NULL,
          `name8` varchar(255) NOT NULL,
          `name9` varchar(255) NOT NULL,
          `name10` varchar(255) NOT NULL,
          `name11` varchar(255) NOT NULL,
          `name12` varchar(255) NOT NULL,
          `name13` varchar(255) NOT NULL,
          `name14` varchar(255) NOT NULL,
          `name15` varchar(255) NOT NULL,
          `name16` varchar(255) NOT NULL,
          `name17` varchar(255) NOT NULL,
          `name18` varchar(255) NOT NULL,
          `name19` varchar(255) NOT NULL,
          `name20` varchar(255) NOT NULL,
          `name21` varchar(255) NOT NULL,
          `name22` varchar(255) NOT NULL,
          `name23` varchar(255) NOT NULL,
          `name24` varchar(255) NOT NULL,
          `name25` varchar(255) NOT NULL,
          `name26` varchar(255) NOT NULL,
          `name27` varchar(255) NOT NULL,
          `name28` varchar(255) NOT NULL,
          `name29` varchar(255) NOT NULL,
          `name30` varchar(255) NOT NULL,
          `field` varchar(50) NOT NULL,
          PRIMARY KEY  (`id`))")
    or error('Critical Error', mysql_error () );

echo 'Custom fields table created<br />';
    
$db->query("CREATE TABLE IF NOT EXISTS `".VALUES_TABLE."` (
          `id` mediumint(5) NOT NULL auto_increment,
          `f_id` mediumint(5) NOT NULL,
          `name` varchar(255) NOT NULL,
          `name2` varchar(255) NOT NULL,
          `name3` varchar(255) NOT NULL,
          `name4` varchar(255) NOT NULL,
          `name5` varchar(255) NOT NULL,
          `name6` varchar(255) NOT NULL,
          `name7` varchar(255) NOT NULL,
          `name8` varchar(255) NOT NULL,
          `name9` varchar(255) NOT NULL,
          `name10` varchar(255) NOT NULL,
          `name11` varchar(255) NOT NULL,
          `name12` varchar(255) NOT NULL,
          `name13` varchar(255) NOT NULL,
          `name14` varchar(255) NOT NULL,
          `name15` varchar(255) NOT NULL,
          `name16` varchar(255) NOT NULL,
          `name17` varchar(255) NOT NULL,
          `name18` varchar(255) NOT NULL,
          `name19` varchar(255) NOT NULL,
          `name20` varchar(255) NOT NULL,
          `name21` varchar(255) NOT NULL,
          `name22` varchar(255) NOT NULL,
          `name23` varchar(255) NOT NULL,
          `name24` varchar(255) NOT NULL,
          `name25` varchar(255) NOT NULL,
          `name26` varchar(255) NOT NULL,
          `name27` varchar(255) NOT NULL,
          `name28` varchar(255) NOT NULL,
          `name29` varchar(255) NOT NULL,
          `name30` varchar(255) NOT NULL,
          PRIMARY KEY  (`id`))")
    or error('Critical Error', mysql_error () );

echo 'Custom field values table created<br />';

// PROPERTIES TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . PROPERTIES_TABLE . ' (
	id int(10) UNSIGNED auto_increment, 
	userid int(10) UNSIGNED DEFAULT \'0\' NOT NULL, 
	approved tinyint(1) UNSIGNED DEFAULT \'0\', 
	featured varchar(1) DEFAULT \'B\' NOT NULL, 
	mls varchar(10) DEFAULT NULL, 
	type smallint(5) UNSIGNED DEFAULT \'0\',
	style smallint(5) UNSIGNED DEFAULT \'0\', 
	status tinyint(1) UNSIGNED DEFAULT \'0\', 
	title varchar(255) DEFAULT NULL, 
	title2 varchar(255) DEFAULT NULL, 
	title3 varchar(255) DEFAULT NULL, 
	title4 varchar(255) DEFAULT NULL, 
	title5 varchar(255) DEFAULT NULL, 
	title6 varchar(255) DEFAULT NULL, 
	title7 varchar(255) DEFAULT NULL, 
	title8 varchar(255) DEFAULT NULL, 
	title9 varchar(255) DEFAULT NULL, 
	title10 varchar(255) DEFAULT NULL, 
	title11 varchar(255) DEFAULT NULL, 
	title12 varchar(255) DEFAULT NULL, 
	title13 varchar(255) DEFAULT NULL, 
	title14 varchar(255) DEFAULT NULL, 
	title15 varchar(255) DEFAULT NULL, 
	title16 varchar(255) DEFAULT NULL, 
	title17 varchar(255) DEFAULT NULL, 
	title18 varchar(255) DEFAULT NULL, 
	title19 varchar(255) DEFAULT NULL, 
	title20 varchar(255) DEFAULT NULL, 
	title21 varchar(255) DEFAULT NULL, 
	title22 varchar(255) DEFAULT NULL, 
	title23 varchar(255) DEFAULT NULL, 
	title24 varchar(255) DEFAULT NULL, 
	title25 varchar(255) DEFAULT NULL, 
	title26 varchar(255) DEFAULT NULL, 
	title27 varchar(255) DEFAULT NULL, 
	title28 varchar(255) DEFAULT NULL, 
	title29 varchar(255) DEFAULT NULL, 
	title30 varchar(255) DEFAULT NULL, 
	description text,
	description2 text,
	description3 text,
	description4 text,
	description5 text,
	description6 text,
	description7 text,
	description8 text,
	description9 text,
	description10 text,
	description11 text,
	description12 text,
	description13 text,
	description14 text,
	description15 text,
	description16 text,
	description17 text,
	description18 text,
	description19 text,
	description20 text,
	description21 text,
	description22 text,
	description23 text,
	description24 text,
	description25 text,
	description26 text,
	description27 text,
	description28 text,
	description29 text,
	description30 text,
	size varchar(50) DEFAULT NULL, 
	dimensions varchar(50) DEFAULT NULL, 
	bedrooms tinyint(2) UNSIGNED DEFAULT \'0\', 
	bathrooms tinyint(2) UNSIGNED DEFAULT \'0\', 
	half_bathrooms tinyint(2) UNSIGNED DEFAULT \'0\', 
	garage smallint(5) UNSIGNED DEFAULT \'0\', 
	garage_cars tinyint(2) UNSIGNED DEFAULT \'0\', 
	basement smallint(5) UNSIGNED DEFAULT \'0\', 
	location2 text, 
	zip varchar(20) DEFAULT NULL, 
	address1 varchar(50) DEFAULT NULL, 
	address2 varchar(50) DEFAULT NULL, 
	display_address char(3) DEFAULT NULL, 
	price bigint(15) UNSIGNED DEFAULT \'0\', 
	directions text, 
	year_built varchar(4) DEFAULT NULL, 
	buildings varchar(255) DEFAULT NULL, 
	appliances varchar(255) DEFAULT NULL, 
	features varchar(255) DEFAULT NULL, 
	date_added varchar(10) DEFAULT NULL, 
	date_updated varchar(10) DEFAULT NULL,
	date_upgraded varchar(10) DEFAULT NULL,
	ip_added text,
	ip_updated text,
	ip_upgraded text,
	hits mediumint(8) UNSIGNED DEFAULT \'0\',
	image_uploaded tinyint(1) UNSIGNED DEFAULT \'0\', 
	banner varchar(255) DEFAULT NULL, 
	video varchar(255) DEFAULT NULL, 
	video2 varchar(255) DEFAULT NULL,
	type2 smallint(5) UNSIGNED DEFAULT \'0\', 
	calendar text, 
	latitude varchar(255), 
	longitude varchar(255), 
	PRIMARY KEY (id),
	KEY userid (userid)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

// New in 3.2.3
$db->query("ALTER TABLE `".PROPERTIES_TABLE."` 
            ADD COLUMN `date_approved` DATETIME NULL DEFAULT NULL AFTER `date_added`")
    or error('Critical Error', mysql_error () );

$db->query("UPDATE `".PROPERTIES_TABLE."` 
            SET `date_approved` = `date_added`
            WHERE approved = 1 AND date_approved IS NULL")
    or error('Critical Error', mysql_error () );

$db->query("ALTER TABLE `".PROPERTIES_TABLE."` 
            ADD COLUMN `custom1` varchar(255) NOT NULL,
            ADD COLUMN `custom2` varchar(255) NOT NULL,
            ADD COLUMN `custom3` varchar(255) NOT NULL,
            ADD COLUMN `custom4` varchar(255) NOT NULL,
            ADD COLUMN `custom5` varchar(255) NOT NULL,
            ADD COLUMN `custom6` varchar(255) NOT NULL,
            ADD COLUMN `custom7` varchar(255) NOT NULL,
            ADD COLUMN `custom8` varchar(255) NOT NULL,
            ADD COLUMN `custom9` varchar(255) NOT NULL,
            ADD COLUMN `custom10` varchar(255) NOT NULL")
    or error('Critical Error', mysql_error () );

echo 'Properties table created<br />';

// GALLERY TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . GALLERY_TABLE . ' (
	id int(10) UNSIGNED auto_increment, 
	userid int(10) UNSIGNED DEFAULT \'0\', 
	listingid int(10) UNSIGNED DEFAULT \'0\', 
	title varchar(255) DEFAULT NULL, 
	description text, 
	date_added varchar(10) DEFAULT NULL, 
	date_updated varchar(10) DEFAULT NULL, 
	ip_added text,
	ip_updated text,
	PRIMARY KEY (id),
	KEY userid (userid),
	KEY listingid (listingid)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Gallery table created<br />';

// LOCATIONS TABLE + DEFAULT VALUES

// 3 level locations
 $db->query('CREATE TABLE IF NOT EXISTS ' . LOCATION1_TABLE . ' (selector int, category text, sccounter int DEFAULT \'0\' NOT NULL, ssccounter int DEFAULT \'0\' NOT NULL, fcounter int DEFAULT \'0\' NOT NULL, top int DEFAULT \'0\' NOT NULL, ip text) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . LOCATION1_TABLE . ' (selector, category) VALUES (1, "United States")') or error('Critical Error', mysql_error () );

 $db->query('CREATE TABLE IF NOT EXISTS ' . LOCATION2_TABLE . ' (catsel int, catsubsel int, subcategory text, ssccounter int DEFAULT \'0\' NOT NULL, fcounter int DEFAULT \'0\' NOT NULL) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . LOCATION2_TABLE . ' (catsel, catsubsel, subcategory) VALUES (1, 1, "Massachusetts")') or error('Critical Error', mysql_error () );
 
 $db->query('CREATE TABLE IF NOT EXISTS ' . LOCATION3_TABLE . ' (catsel int, catsubsel int, catsubsubsel int, subsubcategory text, fcounter int DEFAULT \'0\' NOT NULL) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . LOCATION3_TABLE . ' (catsel, catsubsel, catsubsubsel, subsubcategory) VALUES (1, 1, 1, "Boston")') or error('Critical Error', mysql_error () ); 

// Agent Locations
 $db->query('CREATE TABLE IF NOT EXISTS ' . LOCATIONS_TABLE . ' (name varchar(50) DEFAULT NULL, name2 varchar(50) DEFAULT NULL, name3 varchar(50) DEFAULT NULL, name4 varchar(50) DEFAULT NULL, name5 varchar(50) DEFAULT NULL, name6 varchar(50) DEFAULT NULL, name7 varchar(50) DEFAULT NULL, name8 varchar(50) DEFAULT NULL, name9 varchar(50) DEFAULT NULL, name10 varchar(50) DEFAULT NULL, name11 varchar(50) DEFAULT NULL, name12 varchar(50) DEFAULT NULL, id int(5) UNSIGNED auto_increment, PRIMARY KEY (id)) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );
 
// New in 3.2.1
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name13 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name14 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name15 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name16 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name17 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name18 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name19 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name20 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name21 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name22 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name23 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name24 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name25 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name26 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name27 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name28 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name29 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );
$db->query('ALTER TABLE ' . LOCATIONS_TABLE . ' ADD name30 varchar(50) DEFAULT NULL') or error('Critical Error', mysql_error () );

 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (1, 'Alabama')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (2, 'Alaska')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (3, 'Arizona')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (4, 'Arkansas')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (5, 'California')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (6, 'Colorado')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (7, 'Connecticut')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (8, 'Delaware')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (9, 'District of Columbia')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (10, 'Florida')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (11, 'Georgia')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (12, 'Hawaii')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (13, 'Idaho')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (14, 'Illinois')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (15, 'Indiana')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (16, 'Iowa')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (17, 'Kansas')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (18, 'Kentucky')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (19, 'Louisiana')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (20, 'Maine')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (21, 'Maryland')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (22, 'Massachusetts')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (23, 'Michigan')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (24, 'Minnesota')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (25, 'Mississippi')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (26, 'Missouri')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (27, 'Montana')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (28, 'Nebraska')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (29, 'Nevada')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (30, 'New Hampshire')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (31, 'New Jersey')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (32, 'New Mexico')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (33, 'New York')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (34, 'North Carolina')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (35, 'North Dakota')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (36, 'Ohio')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (37, 'Oklahoma')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (38, 'Oregon')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (39, 'Pennsylvania')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (40, 'Rhode Island')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (41, 'South Carolina')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (42, 'South Dakota')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (43, 'Tennessee')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (44, 'Texas')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (45, 'Utah')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (46, 'Vermont')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (47, 'Virginia')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (48, 'Washington')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (49, 'West Virginia')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (50, 'Wisconsin')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (51, 'Wyoming')");
 mysql_query("INSERT IGNORE INTO " . LOCATIONS_TABLE . " (id, name) VALUES  (52, 'Outside the US')");

echo 'Locations table created and populated (All the US states are added)<br />';

// BUILDINGS TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . BUILDINGS_TABLE . ' (
	name varchar(50) DEFAULT NULL,
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL,
	name4 varchar(50) DEFAULT NULL,
	name5 varchar(50) DEFAULT NULL,
	name6 varchar(50) DEFAULT NULL,
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL, 
	name9 varchar(50) DEFAULT NULL, 
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . BUILDINGS_TABLE . ' (name, id) VALUES ("Barn / Stable", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . BUILDINGS_TABLE . ' (name, id) VALUES ("Boatlift", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . BUILDINGS_TABLE . ' (name, id) VALUES ("Dock / Pier", 3)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . BUILDINGS_TABLE . ' (name, id) VALUES ("Gazebo", 4)') or error('Critical Error', mysql_error () );

echo 'Additional Out Buildings table created and populated<br />';

// APPLIANCES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . APPLIANCES_TABLE . ' (
	name varchar(50) DEFAULT NULL, 
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL,
	name4 varchar(50) DEFAULT NULL, 
	name5 varchar(50) DEFAULT NULL, 
	name6 varchar(50) DEFAULT NULL, 
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL,
	name9 varchar(50) DEFAULT NULL,
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . APPLIANCES_TABLE . ' (name, id) VALUES ("Central Vac", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . APPLIANCES_TABLE . ' (name, id) VALUES ("Compactor Vac", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . APPLIANCES_TABLE . ' (name, id) VALUES ("Disposal", 3)') or error('Critical Error', mysql_error () );

echo 'Appliances table created and populated<br />';

// FEATURES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . FEATURES_TABLE . ' (
	name varchar(50) DEFAULT NULL, 
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL, 
	name4 varchar(50) DEFAULT NULL, 
	name5 varchar(50) DEFAULT NULL, 
	name6 varchar(50) DEFAULT NULL, 
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL, 
	name9 varchar(50) DEFAULT NULL, 
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . FEATURES_TABLE . ' (name, id) VALUES ("9 ft Ceilings", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . FEATURES_TABLE . ' (name, id) VALUES ("Beamed Ceilings", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . FEATURES_TABLE . ' (name, id) VALUES ("Cathedral Ceilings", 3)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . FEATURES_TABLE . ' (name, id) VALUES ("Bay / Bow Windows", 4)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . FEATURES_TABLE . ' (name, id) VALUES ("Breakfast Nook", 5)') or error('Critical Error', mysql_error () );

echo 'Features table created and populated<br />';

// BASEMENT TYPES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . BASEMENT_TABLE . ' (
	name varchar(50) DEFAULT NULL, 
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL, 
	name4 varchar(50) DEFAULT NULL, 
	name5 varchar(50) DEFAULT NULL, 
	name6 varchar(50) DEFAULT NULL, 
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL, 
	name9 varchar(50) DEFAULT NULL, 
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . BASEMENT_TABLE . ' (name, id) VALUES ("Full", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . BASEMENT_TABLE . ' (name, id) VALUES ("Partial", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . BASEMENT_TABLE . ' (name, id) VALUES ("Finished", 3)') or error('Critical Error', mysql_error () );

echo 'Basement types table created and populated<br />';

// GARAGE TYPES TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . GARAGE_TABLE . ' (
	name varchar(50) DEFAULT NULL, 
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL, 
	name4 varchar(50) DEFAULT NULL, 
	name5 varchar(50) DEFAULT NULL, 
	name6 varchar(50) DEFAULT NULL, 
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL, 
	name9 varchar(50) DEFAULT NULL, 
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . GARAGE_TABLE . ' (name, id) VALUES ("Attached", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . GARAGE_TABLE . ' (name, id) VALUES ("Detached", 2)') or error('Critical Error', mysql_error () );

echo 'Garage types table created and populated<br />';

// BANS TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . BANS_TABLE . ' (name varchar(50) DEFAULT NULL, id int(5) UNSIGNED auto_increment, PRIMARY KEY (id)) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Banned e-mails table created and populated<br />';

// RATINGS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . RATINGS_TABLE . ' (ip text, userid int(10) UNSIGNED DEFAULT \'0\', rating mediumint(8) DEFAULT \'0\', date varchar(10) DEFAULT NULL, id int(10) UNSIGNED auto_increment, PRIMARY KEY (id)) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Ratings table created<br />';

// FEATURED AGENTS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . FEATURED_AGENTS_TABLE . ' (id int(10) UNSIGNED, start_date varchar(10) DEFAULT NULL, end_date varchar(10) DEFAULT NULL, featured tinyint(1) UNSIGNED DEFAULT \'0\' NOT NULL, package int(10) UNSIGNED DEFAULT \'0\') CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Featured Agents table created<br />';

// FEATURED LISTINGS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . FEATURED_TABLE . ' (id int(10) UNSIGNED, start_date varchar(10) DEFAULT NULL, end_date varchar(10) DEFAULT NULL, featured tinyint(1) UNSIGNED DEFAULT \'0\' NOT NULL, package int(10) UNSIGNED DEFAULT \'0\') CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Featured Listings table created<br />';

// CRON TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . CRON_TABLE . ' (counter int(15) UNSIGNED DEFAULT \'0\', time varchar(255) DEFAULT NULL) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . CRON_TABLE . ' (counter, time) VALUES (0, "0")') or error('Critical Error', mysql_error () );

echo 'Cron table created and populated<br />';

// ADMINISTRATORS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . ADMINS_TABLE . ' (login varchar(20) DEFAULT NULL, password varchar(32) DEFAULT NULL, level varchar(25) DEFAULT NULL) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . ADMINS_TABLE . ' (login, password, level) VALUES ("admin", "' . md5("admin") . '", "SUPERUSER")') or error('Critical Error', mysql_error () );

echo 'Administrators table created and populated<br />';

// ADMINISTRATOR PRIVELEGES TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . PRIVILEGES_TABLE . ' (

	id smallint(5) UNSIGNED auto_increment, 
	privilege varchar(25) DEFAULT NULL,
	manage_users varchar(3) DEFAULT NULL,
	manage_listings varchar(3) DEFAULT NULL,
	manage_gallery varchar(3) DEFAULT NULL,
	manage_types varchar(3) DEFAULT NULL,
	manage_settings varchar(3) DEFAULT NULL,
	manage_administrators varchar(3) DEFAULT NULL,
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Administrator Privileges table created and populated<br />';


// FEATURED_PACKAGES TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . PACKAGES_TABLE . ' (

	id int(10) UNSIGNED auto_increment, 
	name varchar(255) DEFAULT NULL,
	price varchar(255) DEFAULT NULL,
	days int(10) UNSIGNED DEFAULT \'0\',
	position varchar(255) DEFAULT NULL,
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Featured Packages table created<br />';

// FEATURED_PACKAGES_AGENT TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . PACKAGES_AGENT_TABLE . ' (

	id int(10) UNSIGNED auto_increment, 
	name varchar(255) DEFAULT NULL,
	price varchar(255) DEFAULT NULL,
	days int(10) UNSIGNED DEFAULT \'0\',
	position varchar(255) DEFAULT NULL,
	listings varchar(255) DEFAULT NULL,
	gallery varchar(255) DEFAULT NULL,
	mainimage varchar(255) DEFAULT NULL,
	photo varchar(255) DEFAULT NULL,
	phone varchar(255) DEFAULT NULL,
	address varchar(255) DEFAULT NULL,
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Featured Packages for Agents table created<br />';

// AGENTS ONLINE TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . ONLINE_TABLE . ' (

	id int(10) UNSIGNED auto_increment, 
	username varchar(255) DEFAULT NULL,
	time varchar(255) DEFAULT NULL,
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Agents Online table created<br />';

// LISTING_ALERTS TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . ALERTS_TABLE . ' (

	approved varchar(255) DEFAULT NULL,
	email varchar(255) DEFAULT NULL,
	name varchar(255) DEFAULT NULL,
	type smallint(5) UNSIGNED DEFAULT \'0\',
	zip varchar(255) DEFAULT NULL,
	city varchar(255) DEFAULT NULL,
	code varchar(255) DEFAULT NULL

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Alerts table created<br />';

// PAGES TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . PAGES_TABLE . ' (

	menu varchar(255) DEFAULT NULL,
	menu2 varchar(255) DEFAULT NULL,
	menu3 varchar(255) DEFAULT NULL,
	menu4 varchar(255) DEFAULT NULL,
	menu5 varchar(255) DEFAULT NULL,
	menu6 varchar(255) DEFAULT NULL,
	menu7 varchar(255) DEFAULT NULL,
	menu8 varchar(255) DEFAULT NULL,
	menu9 varchar(255) DEFAULT NULL,
	menu10 varchar(255) DEFAULT NULL,
	menu11 varchar(255) DEFAULT NULL,
	menu12 varchar(255) DEFAULT NULL,
	menu13 varchar(255) DEFAULT NULL,
	menu14 varchar(255) DEFAULT NULL,
	menu15 varchar(255) DEFAULT NULL,
	menu16 varchar(255) DEFAULT NULL,
	menu17 varchar(255) DEFAULT NULL,
	menu18 varchar(255) DEFAULT NULL,
	menu19 varchar(255) DEFAULT NULL,
	menu20 varchar(255) DEFAULT NULL,
	menu21 varchar(255) DEFAULT NULL,
	menu22 varchar(255) DEFAULT NULL,
	menu23 varchar(255) DEFAULT NULL,
	menu24 varchar(255) DEFAULT NULL,
	menu25 varchar(255) DEFAULT NULL,
	menu26 varchar(255) DEFAULT NULL,
	menu27 varchar(255) DEFAULT NULL,
	menu28 varchar(255) DEFAULT NULL,
	menu29 varchar(255) DEFAULT NULL,
	menu30 varchar(255) DEFAULT NULL,
	text text,
	text2 text,
	text3 text,
	text4 text,
	text5 text,
	text6 text,
	text7 text,
	text8 text,
	text9 text,
	text10 text,
	text11 text,
	text12 text,
	text13 text,
	text14 text,
	text15 text,
	text16 text,
	text17 text,
	text18 text,
	text19 text,
	text20 text,
	text21 text,
	text22 text,
	text23 text,
	text24 text,
	text25 text,
	text26 text,
	text27 text,
	text28 text,
	text29 text,
	text30 text,
	status ENUM(\'1\', \'0\') NOT NULL DEFAULT \'1\',
	string varchar(255),
	id int(5) UNSIGNED auto_increment,
	date datetime,
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'CMS table created<br />';

// TYPES2 TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . TYPES2_TABLE . ' (

	name varchar(50) DEFAULT NULL, 
	name2 varchar(50) DEFAULT NULL, 
	name3 varchar(50) DEFAULT NULL, 
	name4 varchar(50) DEFAULT NULL, 
	name5 varchar(50) DEFAULT NULL, 
	name6 varchar(50) DEFAULT NULL, 
	name7 varchar(50) DEFAULT NULL, 
	name8 varchar(50) DEFAULT NULL, 
	name9 varchar(50) DEFAULT NULL, 
	name10 varchar(50) DEFAULT NULL, 
	name11 varchar(50) DEFAULT NULL, 
	name12 varchar(50) DEFAULT NULL, 
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	id int(5) UNSIGNED auto_increment, 
	PRIMARY KEY (id)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . TYPES2_TABLE . ' (name, id) VALUES ("For Sale / Residential", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES2_TABLE . ' (name, id) VALUES ("For Rent / Residential", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES2_TABLE . ' (name, id) VALUES ("For Sale / Commercial", 3)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . TYPES2_TABLE . ' (name, id) VALUES ("For Rent / Commercial", 4)') or error('Critical Error', mysql_error () );

 // New in 3.2.3
 $db->query('ALTER TABLE '.TYPES2_TABLE.' ADD COLUMN class VARCHAR(31) NOT NULL DEFAULT "sale"')    
    or error('Critical Error', mysql_error () );

 $db->query('UPDATE '.TYPES2_TABLE.'
            SET class = "monthly"
            WHERE name LIKE "%rent%" OR name LIKE "%subl%"')
    or error('Critical Error', mysql_error() );
 
echo 'Listing Types table created and populated<br />';

// STATUS TABLE + DEFAULT VALUES

$db->query('CREATE TABLE IF NOT EXISTS ' . STATUS_TABLE . ' (
	name varchar(50) DEFAULT NULL,
	name2 varchar(50) DEFAULT NULL,
	name3 varchar(50) DEFAULT NULL,
	name4 varchar(50) DEFAULT NULL,
	name5 varchar(50) DEFAULT NULL,
	name6 varchar(50) DEFAULT NULL,
	name7 varchar(50) DEFAULT NULL,
	name8 varchar(50) DEFAULT NULL,
	name9 varchar(50) DEFAULT NULL,
	name10 varchar(50) DEFAULT NULL,
	name11 varchar(50) DEFAULT NULL,
	name12 varchar(50) DEFAULT NULL,
	name13 varchar(50) DEFAULT NULL,
	name14 varchar(50) DEFAULT NULL,
	name15 varchar(50) DEFAULT NULL,
	name16 varchar(50) DEFAULT NULL,
	name17 varchar(50) DEFAULT NULL,
	name18 varchar(50) DEFAULT NULL,
	name19 varchar(50) DEFAULT NULL,
	name20 varchar(50) DEFAULT NULL,
	name21 varchar(50) DEFAULT NULL,
	name22 varchar(50) DEFAULT NULL,
	name23 varchar(50) DEFAULT NULL,
	name24 varchar(50) DEFAULT NULL,
	name25 varchar(50) DEFAULT NULL,
	name26 varchar(50) DEFAULT NULL,
	name27 varchar(50) DEFAULT NULL,
	name28 varchar(50) DEFAULT NULL,
	name29 varchar(50) DEFAULT NULL,
	name30 varchar(50) DEFAULT NULL,
	counter int(10) DEFAULT \'0\' NOT NULL,
	id int(5) UNSIGNED auto_increment,
	PRIMARY KEY (id)
) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

 $db->query('INSERT IGNORE INTO ' . STATUS_TABLE . ' (name, id) VALUES ("Available", 1)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . STATUS_TABLE . ' (name, id) VALUES ("Sale Pending", 2)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . STATUS_TABLE . ' (name, id) VALUES ("Under Agreement", 3)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . STATUS_TABLE . ' (name, id) VALUES ("Sold", 4)') or error('Critical Error', mysql_error () );
 $db->query('INSERT IGNORE INTO ' . STATUS_TABLE . ' (name, id) VALUES ("Unavailable", 5)') or error('Critical Error', mysql_error () );

echo 'Property status table created and populated<br />';

// ZIP CODES TABLE

$db->query('CREATE TABLE IF NOT EXISTS ' . ZIP_TABLE . ' (

	zip varchar(5) DEFAULT NULL,
	city varchar(255) DEFAULT NULL,
	state varchar(3) DEFAULT NULL,
	county varchar(255) DEFAULT NULL,
	latitude varchar(255),
	longitude varchar(255)

) CHARACTER SET UTF8') or error('Critical Error', mysql_error () );

echo 'Zip Codes table created<br />';

if (file_exists( PATH . '/install/zip1.php' ) )
 include ( PATH . '/install/zip1.php' );
else
 echo ' Zip codes database file #1 not found<br /> ';

if (file_exists( PATH . '/install/zip2.php' ) )
 include ( PATH . '/install/zip2.php' );
else
 echo ' Zip codes database file #2 not found<br /> ';

if (file_exists( PATH . '/install/zip3.php' ) )
 include ( PATH . '/install/zip3.php' );
else
 echo ' Zip codes database file #3 not found<br /> ';

if (file_exists( PATH . '/install/zip4.php' ) )
 include ( PATH . '/install/zip4.php' );
else
 echo ' Zip codes database file #4 not found<br /> ';

if (file_exists( PATH . '/install/zip5.php' ) )
 include ( PATH . '/install/zip5.php' );
else
 echo ' Zip codes database file #5 not found<br /> ';

if (file_exists( PATH . '/install/zip6.php' ) )
 include ( PATH . '/install/zip6.php' );
else
 echo ' Zip codes database file #6 not found<br /> ';

if (file_exists( PATH . '/install/zip7.php' ) )
 include ( PATH . '/install/zip7.php' );
else
 echo ' Zip codes database file #7 not found<br /> ';

if (file_exists( PATH . '/install/zip8.php' ) )
 include ( PATH . '/install/zip8.php' );
else
 echo ' Zip codes database file #8 not found<br /> ';

echo 'Zip Code table populated (if no error messages above)<br />';

echo '<br /><strong>All the tables have been created successfully.</strong><br /><br />';

$db->close();

?>
    </span></p>

	<p style="font-family : verdana; font-size : 15px; font-weight : bold; color : #5678A2;">Installation Completed!</p>

    <div style="font-family : verdana; font-size : 15px; font-weight : bold; color : #BB5555; margin-bottom: 4em;">
    <dl>
    <dt>Administrative Details:</dt>
        <dd>Username: admin</dd>
        <dd>Password: admin</dd>
    </dl>
    <p>Please remove /install and /docs directories. Once completed, you may <strong><a href="<?php echo URL; ?>">view your web site</a></strong>.</p>
    </div>

	</td>
</tr>
</table>

</div>
</body>
</html>